<?php
class TesteeanswersController extends AppController {

	var $name = 'Testeeanswers';

	function index() {
		$this->Testeeanswer->recursive = 0;
		$this->set('testeeanswers', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid testeeanswer', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('testeeanswer', $this->Testeeanswer->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Testeeanswer->create();
			if ($this->Testeeanswer->save($this->data)) {
				$this->Session->setFlash(__('The testeeanswer has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The testeeanswer could not be saved. Please, try again.', true));
			}
		}
		$tests = $this->Testeeanswer->Test->find('list');
		$questions = $this->Testeeanswer->Question->find('list');
		$choices = $this->Testeeanswer->Choice->find('list');
		$testees = $this->Testeeanswer->Testee->find('list');
		$this->set(compact('tests', 'questions', 'choices', 'testees'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid testeeanswer', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Testeeanswer->save($this->data)) {
				$this->Session->setFlash(__('The testeeanswer has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The testeeanswer could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Testeeanswer->read(null, $id);
		}
		$tests = $this->Testeeanswer->Test->find('list');
		$questions = $this->Testeeanswer->Question->find('list');
		$choices = $this->Testeeanswer->Choice->find('list');
		$testees = $this->Testeeanswer->Testee->find('list');
		$this->set(compact('tests', 'questions', 'choices', 'testees'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for testeeanswer', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Testeeanswer->delete($id)) {
			$this->Session->setFlash(__('Testeeanswer deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Testeeanswer was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}

	/** 
	@author: tuan, do van
	@created: 
	@updated:
	*/

	function score (array $info=null,array $input=null){
		$test_id=$info['test_id'];
		$testee_id=$info['testee_id'];
		$question_id=$info['question_id'];
		
		$this->loadModel('Timecheck');
		$score=$this->Timcheck->check ($tim);
	}
	// return score for $testee_id with $question_id in $test_id
	function scoreKS_ (array $info=null){
	/*
		+ check1: all testeeanswer[choice] have same answerterm
		+ check2: testeeanswer[choices][size] = question[answerterm][choices]['size']	
	*/
		//get info
		$test_id=$info['test_id'];
		$testee_id=$info['testee_id'];
		$question_id=$info['question_id'];
		
		$conditions=array ('Testeeanswer.test_id'=>$test_id,
				'Testeeanswer.testee_id'=>$testee_id,
				'Testeeanswer.question_id'=>$question_id);
		$choicelist=$this->Testeeanswer->find ('all',$conditions);
		//debug ($choicelist);
		$this->loadModel ('Question');
		$conditions=array ('Question.id'=>'1');
		$question=$this->Question->findById  ($question_id);	
		//debug ($question);
		$this->loadModel ('Testeeanswer');
		// check time
		$score=
		$timecheck_id=
		$submitted_time=
		$info = array ('score'=>$score, 
				'timecheck_id'=>$timecheck_id,
				'submitted_time'=>$submitted_time);
		$score=checkTime ($info);
		return score;
	}
	/**
	 * 
	 * @param array $info
	 * @param unknown_type $correct
	 * @return string
	 */
	function scoreKWA_ (array $info){
		//get info
		$test_id=$info['test_id'];
		$testee_id=$info['testee_id'];
		$question_id=$info['question_id'];
		//check time
		$score=
		$timecheck_id=
		$submitted_time=
		$info = array ('score'=>$score,
				'timecheck_id'=>$timecheck_id,
				'submitted_time'=>$submitted_time);
		$score=checkTime ($score,$timecheck_id);
		return score;
	}
	/**
	 * 
	 * @param array $info
	 * @param unknown_type $correct
	 * @return string
	 */
	function scoreKWP_ (array $info, array $input_data){
		;
	}		
}
